package com.slj.service.impl;

import com.slj.entity.Student;
import com.slj.mapper.StudentMapper;
import com.slj.service.StudentService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@RequiredArgsConstructor
public class StudentServiceImpl implements StudentService {
    private final StudentMapper studentMapper;

    @Override
    public Student createStudent(Student student) {
        studentMapper.insert(student);
        return student;
    }

    @Override
    public Student updateStudent(Student student) {
        studentMapper.updateByPrimaryKey(student);
        return student;
    }

    @Override
    public void deleteStudent(Integer studentId) {
        studentMapper.deleteByPrimaryKey(studentId);
    }

    @Override
    public Student getStudentById(Integer studentId) {
        return studentMapper.selectByPrimaryKey(studentId);
    }

    @Override
    public List<Student> getStudentsByClassId(Integer classId) {
        return studentMapper.selectByClassId(classId);
    }

    @Override
    public List<Student> getAllStudents() {
        return studentMapper.selectAll();
    }
    @Override
    public List<Student> searchStudents(String name, Integer classId) {
        return studentMapper.selectStudentsByCondition(name, classId);
    }
}